package com.shareit.ocr.util;

/**  
* 类说明   
*  
* @author geai
* @date 2018年1月25日  新建  
*/
public class JavaScriptUtil {
	
	
	public static String formatSBH(String sbh,String rule) {
		String str = sbh;
		for(String s:rule.split("_")) {
			str = changechar(str,s);
		}
		
		return str;
	}
	
	
	public static String changechar(String str,String s) {
		String tmp =str;
		char a = s.charAt(2);
		char b = s.charAt(0);
		tmp = tmp.replace(a, '#');
		tmp = tmp.replace(b, '%');
		tmp = tmp.replace('#',b);
		tmp = tmp.replace('%', a);
		
		return tmp;
	}
	
	public static String getje(String je,String rule) {
		float r1;
		float r2;
		double r;
		
		if("".equals(je.trim())) {return je;}
		try {
			  Integer.parseInt(je,10);
			  r1 = 0;
			}catch (NumberFormatException e) {
			  r1 = je.split(".")[1].length();
			}
			
		try {
			  Integer.parseInt(rule,10);
			  r2 = 0;
			}catch (NumberFormatException e) {
			  r2 = rule.split(".")[1].length();
			}
		
		double m = Math.pow(10,Math.max(r1, r2));
		r =(Float.parseFloat(je) * m + Float.parseFloat(rule) * m) / m;
		return String.format("%.2f",r);
		
	}
	

}
